home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / libs / ttengine.lha / ttengine-4.1 / Examples / PlainTest / test.c < prev   
C/C++ Source or Header  |  2002-09-29  |  12KB  |  282 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttengine.h>
  10. #include <proto/asl.h>
  11.  
  12. #include <libraries/ttengine.h>
  13.  
  14. extern struct Library *SysBase, *DOSBase;
  15.  
  16. /*----------------------------------------------------------------------------------------------------*/
  17.  
  18. static STRPTR get_font_name(struct Library *AslBase)
  19.   {
  20.     struct FileRequester *freq;
  21.     STRPTR name = NULL;
  22.  
  23.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  24.       {
  25.         if (AslRequestTags(freq,
  26.           ASLFR_TitleText, (ULONG)"Select TrueType font",
  27.           ASLFR_InitialDrawer, (ULONG)"FONTS:",
  28.           ASLFR_DoPatterns, TRUE,
  29.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  30.           ASLFR_RejectIcons, TRUE,
  31.           TAG_END))
  32.           {
  33.             ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
  34.  
  35.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  36.               {
  37.                 strncpy(name, freq->fr_Drawer, namelen);
  38.                 AddPart(name, freq->fr_File, namelen);
  39.               }
  40.           }
  41.         FreeAslRequest(freq);
  42.       }
  43.     return name;
  44.   }
  45.  
  46. /*----------------------------------------------------------------------------------------------------*/
  47.  
  48. static VOID free_font_name(STRPTR name)
  49.   {
  50.     if (name) FreeVec(name);
  51.   }
  52.  
  53. /*----------------------------------------------------------------------------------------------------*/
  54.  
  55. UWORD tx[] = {'T', 'e', 's', 't', ' ', '1', '6', '-', 'b', 'i', 't', ' ', 'U', 'n', 'i',
  56.  'c', 'o', 'd', 'e', ' ', 's', 't', 'r', 'i', 'n', 'g', '.', 0x0000};
  57.  
  58. int Main (void)
  59.   {
  60.     struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase;
  61.     struct Window *win;
  62.     STRPTR fontname;
  63.     APTR font;
  64.  
  65.     if (GfxBase = OpenLibrary("graphics.library", 39))
  66.       {
  67.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  68.           {
  69.             if (AslBase = OpenLibrary("asl.library", 38))
  70.               {
  71.                 if (fontname = get_font_name(AslBase))
  72.                   {
  73.                     if (TTEngineBase = OpenLibrary("ttengine.library", 4))
  74.                       {
  75.                         if (win = OpenWindowTags(NULL,
  76.                           WA_Top, 25,
  77.                           WA_Left, 0,
  78.                           WA_Width, 640,
  79.                           WA_Height, 350,
  80.                           WA_CloseGadget, TRUE,
  81.                           WA_DragBar, TRUE,
  82.                           WA_DepthGadget, TRUE,
  83.                           WA_IDCMP, IDCMP_CLOSEWINDOW,
  84.                           WA_Title, (ULONG)"ttengine.library test",
  85.                           TAG_END))
  86.                           {
  87.                             ULONG sigmask, signals;
  88.                             BOOL running = TRUE;
  89.                             struct RastPort *rp = win->RPort;
  90.  
  91.                             if (font = TT_OpenFont(
  92.                               TT_FontFile, (ULONG)fontname,
  93.                               TT_FontSize, 24,
  94.                             TAG_END))
  95.                               {
  96.                                 TT_SetFont(rp, font);
  97.                                 TT_SetAttrs(rp, TT_Window, (ULONG)win, TAG_END);
  98.  
  99.                                 SetAPen(rp, 2);
  100.                                 SetDrMd(rp, JAM1);
  101.                                 Move(rp, 10, 50);
  102.                                 TT_Text(rp, "This is a text printed with TT_Text().", 38);
  103.  
  104.                                 TT_SetAttrs(rp,
  105.                                   TT_Antialias, TT_Antialias_Off,
  106.                                   TT_Encoding, TT_Encoding_Unicode,
  107.                                 TAG_END);
  108.  
  109.                                 SetDrMd(rp, JAM2);
  110.                                 SetBPen(rp, 3);
  111.                                 Move(rp, 10, 74);
  112.                                 TT_Text(rp, tx, 27);
  113.  
  114.                                 TT_CloseFont(font);
  115.                               }
  116.                             else PutStr("Font open failed.\n");
  117.  
  118.                             if (font = TT_OpenFont(
  119.                               TT_FontFile, (ULONG)fontname,
  120.                               TT_FontSize, 36,
  121.                             TAG_END))
  122.                               {
  123.                                 TT_SetFont(rp, font);
  124.                                 TT_SetAttrs(rp,
  125.                                   TT_Encoding, TT_Encoding_Default,
  126.                                   TT_Antialias, TT_Antialias_On,
  127.                                   TT_Window, (ULONG)win,
  128.                                 TAG_END);
  129.  
  130.                                 SetAPen(rp, 1);
  131.                                 SetBPen(rp, 2);
  132.                                 SetDrMd(rp, JAM2);
  133.                                 Move(rp, 10, 120);
  134.                                 TT_Text(rp, "Antialias with 36 points size.", 30);
  135.  
  136.                                 TT_CloseFont(font);
  137.                               }
  138.                             else PutStr("Font open failed.\n");
  139.  
  140.                             if (font = TT_OpenFont(
  141.                               TT_FontFile, (ULONG)fontname,
  142.                               TT_FontSize, 16,
  143.                             TAG_END))
  144.                               {
  145.                                 TT_SetFont(rp, font);
  146.                                 TT_SetAttrs(rp,
  147.                                   TT_Encoding, TT_Encoding_Default,
  148.                                   TT_Antialias, TT_Antialias_On,
  149.                                   TT_Window, (ULONG)win,
  150.                                 TAG_END);
  151.  
  152.                                 SetAPen(rp, 1);
  153.                                 SetDrMd(rp, JAM1);
  154.                                 Move(rp, 10, 140);
  155.                                 TT_Text(rp, "Antialias with 16 points size.", 30);
  156.                                 SetAPen(rp, 2);
  157.                                 Move(rp, 10, 156);
  158.                                 TT_Text(rp, "Antialias with 16 points size.", 30);
  159.                                 SetAPen(rp, 3);
  160.                                 Move(rp, 10, 172);
  161.                                 TT_Text(rp, "Antialias with 16 points size.", 30);
  162.  
  163.                                 TT_CloseFont(font);
  164.                               }
  165.                             else PutStr("Font open failed.\n");
  166.  
  167.                             /* antialias on different backgrounds */
  168.  
  169.                             if (font = TT_OpenFont(
  170.                               TT_FontFile, (ULONG)fontname,
  171.                               TT_FontSize, 24,
  172.                             TAG_END))
  173.                               {
  174.                                 ULONG red, grn, blu;
  175.  
  176.                                 red = ObtainBestPen(win->WScreen->ViewPort.ColorMap, 0xFFFFFFFF, 0, 0, TAG_END);
  177.                                 grn = ObtainBestPen(win->WScreen->ViewPort.ColorMap, 0, 0xFFFFFFFF, 0, TAG_END);
  178.                                 blu = ObtainBestPen(win->WScreen->ViewPort.ColorMap, 0, 0, 0xFFFFFFFF, TAG_END);
  179.  
  180.                                 TT_SetFont(rp, font);
  181.                                 TT_SetAttrs(rp,
  182.                                   TT_Encoding, TT_Encoding_Default,
  183.                                   TT_Antialias, TT_Antialias_On,
  184.                                   TT_Window, (ULONG)win,
  185.                                 TAG_END);
  186.  
  187.                                 SetDrMd(rp, JAM2);
  188.  
  189.                                 SetBPen(rp, grn);
  190.                                 Move(rp, 10, 200);
  191.                                 SetAPen(rp, red);
  192.                                 TT_Text(rp, "Smooth47", 8);
  193.                                 SetAPen(rp, blu);
  194.                                 TT_Text(rp, "Smooth47", 8);
  195.                                 SetAPen(rp, 1);
  196.                                 TT_Text(rp, "Smooth47", 8);
  197.                                 SetAPen(rp, 2);
  198.                                 TT_Text(rp, "Smooth47", 8);
  199.  
  200.                                 SetBPen(rp, red);
  201.                                 Move(rp, 10, 224);
  202.                                 SetAPen(rp, grn);
  203.                                 TT_Text(rp, "Smooth47", 8);
  204.                                 SetAPen(rp, blu);
  205.                                 TT_Text(rp, "Smooth47", 8);
  206.                                 SetAPen(rp, 1);
  207.                                 TT_Text(rp, "Smooth47", 8);
  208.                                 SetAPen(rp, 2);
  209.                                 TT_Text(rp, "Smooth47", 8);
  210.  
  211.                                 SetBPen(rp, blu);
  212.                                 Move(rp, 10, 248);
  213.                                 SetAPen(rp, red);
  214.                                 TT_Text(rp, "Smooth47", 8);
  215.                                 SetAPen(rp, grn);
  216.                                 TT_Text(rp, "Smooth47", 8);
  217.                                 SetAPen(rp, 1);
  218.                                 TT_Text(rp, "Smooth47", 8);
  219.                                 SetAPen(rp, 2);
  220.                                 TT_Text(rp, "Smooth47", 8);
  221.  
  222.                                 SetBPen(rp, 1);
  223.                                 Move(rp, 10, 272);
  224.                                 SetAPen(rp, red);
  225.                                 TT_Text(rp, "Smooth47", 8);
  226.                                 SetAPen(rp, grn);
  227.                                 TT_Text(rp, "Smooth47", 8);
  228.                                 SetAPen(rp, blu);
  229.                                 TT_Text(rp, "Smooth47", 8);
  230.                                 SetAPen(rp, 2);
  231.                                 TT_Text(rp, "Smooth47", 8);
  232.  
  233.                                 SetBPen(rp, 2);
  234.                                 Move(rp, 10, 296);
  235.                                 SetAPen(rp, red);
  236.                                 TT_Text(rp, "Smooth47", 8);
  237.                                 SetAPen(rp, grn);
  238.                                 TT_Text(rp, "Smooth47", 8);
  239.                                 SetAPen(rp, 1);
  240.                                 TT_Text(rp, "Smooth47", 8);
  241.                                 SetAPen(rp, blu);
  242.                                 TT_Text(rp, "Smooth47", 8);
  243.  
  244.                                 ReleasePen(win->WScreen->ViewPort.ColorMap, red);
  245.                                 ReleasePen(win->WScreen->ViewPort.ColorMap, grn);
  246.                                 ReleasePen(win->WScreen->ViewPort.ColorMap, blu);
  247.  
  248.                                 TT_CloseFont(font);
  249.                               }
  250.                             else PutStr("Font open failed.\n");
  251.  
  252.                             sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  253.                             while (running)
  254.                               {
  255.                                 signals = Wait(sigmask);
  256.                                 if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  257.                                 if (signals & (1 << win->UserPort->mp_SigBit))
  258.                                   {
  259.                                     struct IntuiMessage *imsg;
  260.  
  261.                                     while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  262.                                       {
  263.                                         if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  264.                                         ReplyMsg((struct Message*)imsg);
  265.                                       }
  266.                                   }
  267.                               }
  268.                             CloseWindow(win);
  269.                           }
  270.                         CloseLibrary(TTEngineBase);
  271.                       }
  272.                     free_font_name(fontname);
  273.                   }
  274.                 CloseLibrary(AslBase);
  275.               }
  276.             CloseLibrary(IntuitionBase);
  277.           }
  278.         CloseLibrary(GfxBase);
  279.       }
  280.     return 0;
  281.   }
  282.